package test.examation;

import java.util.*;
import java.util.regex.Pattern;

public class 浪潮 {
    //浪潮2021提前批笔试，石头，砍掉的树
    //https://www.nowcoder.com/discuss/450255?type=post&order=create&pos=&page=1&channel=1013&source_id=search_post
    public static void main(String args[]){
        //m1();
        //m2();//给几个ip模式规则（只有.）,判断给定Ip是否符合规则
        //m3();//正确使用迭代器删除集合元素


        stone();

        /*int[] array = {9, 15, 27, 35, 6};
        tree(array);*/


    }

    private static void tree(int []array) {


        int[] odd = new int[50];
        int[] even = new int[50];
        int[] nums = new int[100 - array.length];
        Arrays.sort(array);

        //在100个值里把砍掉的树去掉，即去掉array数组元素
        int m = 0, n = 0;
        for (int i = 1; i <= 100; i++) {
            if (m < array.length && i == array[m]) {
                m++;
            } else {
                nums[n++] = i;
            }
        }

        //将所有的树按奇数偶数分开
        m = 0;
        n = 0;
        for (int i = 0; i < nums.length; i++) {
            if (nums[i] % 2 == 0) {
                even[m++] = nums[i];
            } else {
                odd[n++] = nums[i];
            }
        }
        getMaxLen(even, odd);
    }

    public static void getMaxLen(int[] even, int[] odd) {
        int oddMaxLen = odd[0], oddStart = 0;
        int l = 0;
        for (int i = 1; i < odd.length; i++) {
            if (odd[i] - odd[i - 1] == 2) {
                continue;
            } else {
                //如果奇数区间发生更新，则更新区间值和区间左起始点
                if (i - l > oddMaxLen) {
                    oddMaxLen = i - l;
                    oddStart = l;
                }
                l = i;
            }
        }
        l = 0;
        int evenMaxLen = even[0],evenStart=0;
        for (int j = 1; j < even.length; j++) {
            if (even[j] - even[j - 1] == 2) {
                continue;
            } else {
                if (j - l > evenMaxLen) {
                    evenMaxLen = j - l;
                    evenStart = l;
                }
                l = j;
            }
        }
        if (oddMaxLen > evenMaxLen) {
            System.out.println(odd[oddStart] + " " + oddMaxLen);
        } else {
            System.out.println(even[evenStart] + " " + evenMaxLen);
        }
    }


    private static void stone() {
        int max=0;
        int label=0;
        Scanner input=new Scanner(System.in);
        int n=input.nextInt();
        int[] r=new int[n];
        for(int i=0;i<n;i++)
            r[i]=input.nextInt();
        int[] dp=new int[n+1];
        dp[0]=0;
        for(int i=0;i<n-1;i++)
        {
            for(int j=i+1;j<n;j++) {
                int a=i;
                if (r[j] - r[a] == 1||r[j] - r[a] == 0) {
                    dp[j] = dp[a]+ 1;
                    if (max < dp[j])
                        max = dp[j];
                    a = j;
                }
            }

        }
        System.out.println(n-max-1);
    }


    private static void m3() {
        List<Integer> list=new ArrayList<>();
        list.add(10);
        list.add(16);
        list.add(13);
        list.add(12);
        Iterator<Integer> iterator = list.iterator();
        while(iterator.hasNext()){
            Integer next = iterator.next();
            if(next.equals(12)) iterator.remove();
        }
        for(int i:list){
            System.out.println(i);
        }
    }

    private static void m2() {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int m=sc.nextInt();
        String []roles=new String[n];

        for(int i=0;i<n;i++){
            roles[i]=sc.nextLine();
        }
        while(m>0){
            String tmp=sc.nextLine();
            System.out.println(handler(roles,tmp)+" ");
        }
        sc.close();
    }

    private static void m1() {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int m=sc.nextInt();
        int res[]=new int[n];
        int base=m;

        while(m>0){

            int l=sc.nextInt();
            int r=sc.nextInt();
            //将下标之间的槽位赋值

            for(int k=l;k<=r;k++){
                res[k]=base-m+1;
            }
            m--;
        }
        int ans=0;
        for(int i=0;i<res.length;i++){
            ans+=i*res[i]%100000009;
        }
        System.out.println(ans);
        sc.close();
    }
    public static int handler(String []roles,String ip){
        for(int i=0;i<roles.length;i++){
            if(Pattern.matches(roles[i],ip)) return 1;
        }
        return 0;
    }
}